﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 拖动文件到窗口
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            Console.WriteLine("拖动东西到Form窗口");
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            Console.WriteLine($"files.length:{files.Length}");
            StringBuilder sb = new StringBuilder();
            foreach (var filepath in files)
            {
                sb.Append(filepath).Append(Environment.NewLine);
            }
            lbResult.Text = sb.ToString();
        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            Console.WriteLine("Form1_DragEnter 事件called！");
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Link;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
    }
}
